package zzjson.rabbitmq.confirm;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import zzjson.rabbitmq.BaseRabbitMq;

import java.io.IOException;

/**
 * <p>****************************************************************************</p>
 * <p><b>Copyright © 2010-2019 shuncom team All Rights Reserved<b></p>
 * <ul style="margin:15px;">
 * <li>Description : zzjson.rabbitmq.confirm</li>
 * <li>Version     : 1.0.0</li>
 * <li>Creation    : 2019年04月29日</li>
 * <li>@author     : zzy0_0</li>
 * </ul>
 * <p>****************************************************************************</p>
 */
public class NormalConfirmProducer {
	private final static String QUEUE_NAME = "ORIGIN_QUEUE";

	public static void main(String[] args) throws IOException, InterruptedException {
		Connection conn = BaseRabbitMq.getConn();
		Channel channel = conn.createChannel();

		String msg = "Hello world, Rabbit MQ ,Normal Confirm";

		// 声明队列（默认交换机AMQP default，Direct）
		// String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments
		channel.queueDeclare(QUEUE_NAME, false, false, false, null);

		// 开启发送方确认模式
		channel.confirmSelect();

		channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
		// 普通Confirm，发送一条，确认一条
		if (channel.waitForConfirms()) {
			System.out.println("消息发送成功");
		}

		BaseRabbitMq.close(channel, conn);
	}
}